from lib.download import download_douyin
from lib.convert import video_to_audio, audio_to_text, douyin_to_xhs_text
from lib.upload import upload_to_cos
from lib.config import config
from lib.utils import get_logger
from lib.generate import generate_image_by_text
from lib.watermask import remove_watermask
from lib.publish import publish_to_weibo
from lib.db import save_weibo

logger = get_logger(__name__)

if __name__ == "__main__":
    video_paths = download_douyin("脆桃")
    for video_path in video_paths:
        audio_path = video_to_audio(video_path)
        audio_url = upload_to_cos(audio_path, config.cos_bucket)
        text = audio_to_text(audio_url)
        xhs_content, xhs_title, xhs_tags = douyin_to_xhs_text(text)
        image_path = generate_image_by_text(xhs_title, xhs_content)
        image_path = remove_watermask(image_path)
        logger.info(f"image_path: {image_path}")
        publish_to_weibo(xhs_title, xhs_content, xhs_tags, image_path)
        save_weibo(xhs_title, xhs_content, xhs_tags, image_path)
